package com.qy137.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qy137.dao.MemberDao;
import com.qy137.entity.Member;
import com.qy137.service.MemberService;
import com.qy137.vo.CommonResult;
import com.qy137.vo.StudentVo;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;

/**
 * @program: qy137-java
 * @description:
 * @author: 李冠
 * @create: 2021-10-19 18:46
 **/
@Service
public class MemberServiceImpl implements MemberService {

    @Resource
    private MemberDao memberDao;

    @Override
    public CommonResult getStudentAll(Integer page, Integer limit, StudentVo studentVo) {
        Page<Member> page1 = new Page<>(page, limit);
        QueryWrapper<Member> wrapper = new QueryWrapper<>();
        if(StringUtils.isNotEmpty(studentVo.getMobile())){
            wrapper.like("mobile",studentVo.getMobile());
        }
        if(StringUtils.isNotEmpty(studentVo.getNickname())){
            wrapper.like("nickname",studentVo.getNickname());
        }
        if(StringUtils.isNotEmpty(studentVo.getIsDisabled())){
            wrapper.eq("is_disabled",studentVo.getIsDisabled());
        }
        if(studentVo.getGmtCreate().size()!=0){
             wrapper.ge("gmt_create",studentVo.getGmtCreate().get(0));
             wrapper.le("gmt_create",studentVo.getGmtCreate().get(1));
        }

        Page<Member> memberPage = memberDao.selectPage(page1, wrapper);
        return new CommonResult(2000,"查询成功",memberPage);
    }

    @Override
    public CommonResult modifyStudentInformation(Member member) {
        member.setGmtModified(LocalDateTime.now());
        int i = memberDao.updateById(member);
        if(i>0){
            return new CommonResult(2000,"修改成功",null);
        }
        return new CommonResult(5000,"修改失败",null);
    }

    @Override
    public CommonResult stateChange(Boolean isDisabled, String id) {
        Member member = new Member();
        member.setId(id);
        member.setIsDisabled(isDisabled);
        int i = memberDao.updateById(member);
        if(i>0){
            return new CommonResult(2000,"修改成功",null);
        }
        return new CommonResult(5000,"修改失败",null);
    }

    ;






}
